<template>
	<el-dialog title="流程回退对话框" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<scTable ref="table" :data="stepList" height="auto" @row-click="singleElection"  paginationLayout="total, prev, pager, next" hideDo>
				<el-table-column label="备选步骤" prop="stepName" :show-overflow-tooltip="true">
					<template #default="scope">
						<el-radio class="radio" v-model="form.stepRunId" :label="scope.row.stepRunId" style="margin-right: 10px"></el-radio>{{scope.row.stepName}}
					</template>
				</el-table-column>
				<el-table-column label="主办人" prop="opUserName" width="100"></el-table-column>
				<el-table-column label="办理时间" prop="endTime" width="150"></el-table-column>
			</scTable>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			stepList:[],
			//表单数据
			form: {
				stepRunId: '',
				targetStepRunId: "",
				runId: "",
			},
			//验证规则
			rules: {

			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		singleElection(row)
		{
			this.form.targetStepRunId = row.stepRunId;
		},
		async getCanGoBackStepList(runId){
			var res = await this.$API.bpm.bpmStepRun.getCanGoBackStepList.get({runId:runId});
			if (res.code == 200) {
				this.stepList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.bpm.bpmStepRun.setAnyStepGoBackOpt.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.runId = data.runId
			this.form.stepRunId = data.stepRunId,
			this.getCanGoBackStepList(data.runId);
		},
	}
}
</script>

<style scoped>
:deep(.el-radio__label){
	display: none;
}
</style>
